import * as echarts from 'echarts'
const background = '#051a3e' //背景
// 暂无数据
export const blankOption = {
     backgroundColor: background,
     graphic: {
          elements: [
               {
                    type: 'text',
                    left: 'center',
                    top: 'center',
                    style: {
                         text: '暂无数据',
                         fontSize: 40,
                         fontWeight: 'bold',
                         lineDash: [0, 200],
                         lineDashOffset: 0,
                         fill: 'transparent',
                         stroke: '#fff',
                         lineWidth: 1,
                    },
                    keyframeAnimation: {
                         loop: false,
                         keyframes: [
                              {
                                   percent: 1,
                                   style: {
                                        fill: 'white',
                                   },
                              },
                         ],
                    },
               },
          ],
     },
}

export const getTreeOption = (data: any = []) => {
     const option = {
          backgroundColor: background,
          tooltip: {
               trigger: 'item',
               triggerOn: 'mousemove',
               formatter: function (params: any) {
                    return params.marker + params.data.label + '<br>' + '任务总量：' + params.data.total
               },
          },
          series: [
               {
                    type: 'tree',
                    edgeShape: 'polyline', // 链接线是折现还是曲线
                    orient: 'LR',
                    roam: true,
                    top: '5%',
                    left: '20%',
                    right: '20%',
                    bottom: '10%',
                    data: data,
                    symbolSize: 10, // 增大节点大小
                    initialTreeDepth: 10,
                    expandAndCollapse: false,
                    label: {
                         normal: {
                              position: 'left',
                              align: 'center',
                              padding: [10, 20],
                              fontWeight: 'bold',
                              formatter: function (param: any) {
                                   const str = `{label|${param.data.label} ${param.data.total}} `
                                   return str
                              },
                              rich: {
                                   label: {
                                        color: '#FFF',
                                        fontSize: 18,
                                        fontFamily: 'Microsoft YaHei',
                                        verticalAlign: 'top',
                                        position: 'top',
                                        backgroundColor: '#00589b',
                                        borderColor: '#21defb',
                                        shadowColor: '#21defb',
                                        borderWidth: 1,
                                        shadowBlur: 20,
                                        borderRadius: 5,
                                        shadowOffsetY: 2,
                                        shadowOffsetX: 2,
                                        padding: [10, 15],
                                   },
                                   highlight: {
                                        color: '#ff0', // 高亮颜色
                                        fontSize: 20, // 加大字体
                                        fontWeight: 'bold', // 加粗字体
                                        align: 'center',
                                        padding: [10, 20],
                                        backgroundColor: '#ff0000', // 高亮背景颜色
                                        borderRadius: 5,
                                        shadowBlur: 10,
                                        shadowColor: '#000',
                                        shadowOffsetX: 0,
                                        shadowOffsetY: 0,
                                   },
                              },
                         },
                    },

                    lineStyle: {
                         color: '#1a8cc0',
                         width: 2, // 增加线条宽度
                    },
                    animationDuration: 550,
                    animationDurationUpdate: 750,
               },
          ],
     }
     return option
}
